{% extends "admin/layout.html" %}

{% block admin_content %}
<div class="users-content">
    <div class="section-header">
        <h1>User Management</h1>
    </div>

    <div class="section">
        <div class="table-responsive">
            <table class="admin-table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>Name</th>
                        <th>Email</th>
                        <th>Type</th>
                        <th>Status</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for user in users %}
                    <tr>
                        <td>{{ user.id }}</td>
                        <td>{{ user.name }}</td>
                        <td>{{ user.email }}</td>
                        <td>{{ user.user_type }}</td>
                        <td>{{ user.status }}</td>
                        <td>
                            <button class="btn btn-small" onclick="updateUserStatus({{ user.id }}, 'active')">Activate</button>
                            <button class="btn btn-small btn-danger" onclick="updateUserStatus({{ user.id }}, 'suspended')">Suspend</button>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>

<style>
.admin-table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table th,
.admin-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.admin-table th {
    background-color: #f8fafc;
    font-weight: 600;
}

.table-responsive {
    overflow-x: auto;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    transition: all 0.3s ease;
}

.btn-small {
    padding: 0.25rem 0.5rem;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}
</style>

<script>
function updateUserStatus(userId, status) {
    if (confirm('Are you sure you want to update the user status?')) {
        fetch(`/api/users/${userId}/status`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ status: status })
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                location.reload();
            } else {
                alert('Failed to update status: ' + data.message);
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('An error occurred. Please try again later.');
        });
    }
}
</script>
{% endblock %} 